#include<bits/stdc++.h>
using namespace std;
char a[3005][3005];
int per[3005][3005],net[3005][3005];
long long ans;
int u[3005][3005],d[3005][3005];
int sum[3005][3005][4];
void fen(int ax,int ay,int sx,int sy){
	if(ax>=ay||sx>=sy) return;
	if(ay-ax<sy-sx){
		int mid=(sy+sx)/2,jl=sy-sx+1;
		for(int i=ax;i<=ay;i++)for(int j=0;j<=jl;j++)sum[i][j][0]=sum[i][j][1]=sum[i][j][2]=sum[i][j][3]=0;
		for(int i=ax;i<=ay;i++){
			int L=mid-per[i][mid]+1,R=mid+net[i][mid]-1;
			L=max(L,sx),R=min(R,sy);
			for(int j=L;j<=R;j++){
				if(j<=mid){sum[i][min(jl,d[i][j])][0]++;sum[i][min(u[i][j],jl)][2]++;}
				else sum[i][min(jl,d[i][j])][1]++,sum[i][min(u[i][j],jl)][3]++;
			}
			for(int j=jl-1;j;j--) sum[i][j][0]+=sum[i][j+1][0],sum[i][j][1]+=sum[i][j+1][1],sum[i][j][2]+=sum[i][j+1][2],sum[i][j][3]+=sum[i][j+1][3];
		}
		for(int i=ax;i<=ay;i++){
			for(int j=i+1;j<=ay;j++){
				if(a[i][mid]!=a[j][mid]) continue;
				int num=sum[i][(j-i+1)][0],num1=sum[i][j-i+1][1];
				if(per[i][mid]>per[j][mid]) num=sum[j][j-i+1][2];
				if(net[i][mid]>net[j][mid]) num1=sum[j][j-i+1][3];
				ans=(ans+num*num1*1ll);
			}
		}
		fen(ax,ay,sx,mid);fen(ax,ay,mid+1,sy);
	}
	else{
		int mid=(ay+ax)/2,jl=ay-ax+1;
		for(int i=sx;i<=sy;i++)for(int j=0;j<=jl;j++)sum[i][j][0]=sum[i][j][1]=sum[i][j][2]=sum[i][j][3]=0;
		for(int i=sx;i<=sy;i++){
			int L=mid-u[mid][i]+1,R=mid+d[mid][i]-1;
			L=max(L,ax),R=min(R,ay);
			for(int j=L;j<=R;j++){
				if(j<=mid){sum[i][min(jl,net[j][i])][0]++;sum[i][min(per[j][i],jl)][2]++;}
				else sum[i][min(jl,net[j][i])][1]++,sum[i][min(per[j][i],jl)][3]++;
			}
			for(int j=jl-1;j>=0;j--) sum[i][j][0]+=sum[i][j+1][0],sum[i][j][1]+=sum[i][j+1][1],sum[i][j][2]+=sum[i][j+1][2],sum[i][j][3]+=sum[i][j+1][3];
		}
		for(int i=sx;i<=sy;i++){
			for(int j=i+1;j<=sy;j++){
				if(a[mid][i]!=a[mid][j]) continue;
				int num=sum[i][(j-i+1)][0],num1=sum[i][j-i+1][1];
//				cout<<i<<" "<<j<<" "<<num<<" "<<num1<<'\n';
				if(u[mid][i]>u[mid][j]) num=sum[j][j-i+1][2];
				if(d[mid][i]>d[mid][j]) num1=sum[j][j-i+1][3];
//				cout<<i<<" "<<j<<" "<<num<<" "<<num1<<'\n';
				ans=(ans+num*num1*1ll);
			}
		}
//		cout<<ax<<" "<<ay<<" "<<sx<<" "<<sy<<" "<<ans<<'\n';
		fen(ax,mid,sx,sy);fen(mid+1,ay,sx,sy);
	}
}
signed main(){
	freopen("star.in","r",stdin);
	freopen("star.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int n,m;cin>>n>>m;
	for(int i=1;i<=n;i++){for(int j=1;j<=m;j++)cin>>a[i][j];}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]==a[i][j-1])per[i][j]=per[i][j-1]+1;
			else per[i][j]=1;
			if(a[i][j]==a[i-1][j]) u[i][j]=u[i-1][j]+1;
			else u[i][j]=1;
		}
		for(int j=m;j>=1;j--){
			if(a[i][j]==a[i][j+1]) net[i][j]=net[i][j+1]+1;
			else net[i][j]=1;
		}
	}
	for(int i=n;i>=1;i--){
		for(int j=1;j<=m;j++){
			if(a[i][j]==a[i+1][j])d[i][j]=d[i+1][j]+1;
			else d[i][j]=1;
		}
	}
	fen(1,n,1,m);
	cout<<ans;
	return 0;
}
